package com.xqx.service.impl;

import com.xqx.dao.UserDao;
import com.xqx.dao.impl.UserDaoImpl;
import com.xqx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @author：xingquanxiang createTime：2019/10/2 14:25
 * description:
 */
// @Component("userService")
@Service("userService")
// @Scope("prototype")
// @Scope("singleton")
public class UserServiceImpl implements UserService {
    @Value("${jdbc.username}")
    private String username;
    /**
     * 按照数据类型从Spring容器中进行匹配
     */
    // @Autowired
    /**
     * 按照id值从Spring容器中进行匹配，但@Qualifier要结合@Autowired一起使用
     */
    // @Qualifier("userDao")
    @Resource(name = "userDao")  //@Resource相当于 @Qualifier结合@Autowired
    private UserDao userDao;

    @Override
    public void save() {
        System.out.println("username = " + username);
        System.out.println("service save running...");
        userDao.save();
    }

    @PostConstruct
    public void init() {
        System.out.println("init running...");
    }


}
